package com.xopencode.netty.mcb;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Mcb
 * @date 2023/6/11
 * @apiNote
 */
public class NettyServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9000);
        while (true) {
            System.out.println("等待链接");
            Socket client = serverSocket.accept();
            System.out.println("客户端链接");
            new Thread(() -> {

            }).start();
        }
    }

    public static void handler(Socket clientSocket) throws IOException {
        //如果超过1024会如何？
        byte[] bytes = new byte[1024];
        System.out.println("read");
        int read = clientSocket.getInputStream().read(bytes);
        System.out.println("read end");
        if (read != -1) {
            System.out.println("接收的客户端数据：" + new String(bytes, 0, read));
        }
    }
}
